package part14_迭代器模式_统一遍历问题;

import java.util.Iterator;
import java.util.List;

/**
 * @ClassName: Output
 * @Author: AllenSun
 * @Date: 2020/3/8 14:12
 */
public class Output {
    //学院的集合
    List<Colleage> colleageList;

    public Output(List<Colleage> colleageList) {
        this.colleageList = colleageList;
    }

    //遍历所有的学院，然后调用printDepartment输出各个学院的系
    public void printCollege(){
        Iterator<Colleage> iterator=colleageList.iterator();
        while (iterator.hasNext()){
            Colleage colleage=iterator.next();
            System.out.println("======"+colleage.getName()+"======");
            printDepartment(colleage.createIterator());
        }
    }

    //输出学院，输出系
    public void printDepartment(Iterator iterator){
        while (iterator.hasNext()){
            Department d= (Department) iterator.next();
            System.out.println(d.getName());
        }
    }

}
